In a segmented architecture computer, a far pointer is a pointer which includes a segment selector, making it possible to point to addresses outside of the current segment.
For example, in an Intel 8086, where an ordinary pointer is just a 16-bit offset within an implied segment, a far pointer has two parts: a 16-bit segment value and a 16-bit offset value. A linear address is obtained by shifting the binary segment value four times to the left, and then adding the offset value. Hence the effective address is 20 bits (actually 21-bit, which led to the address wraparound and the Gate A20). Comparison and arithmetic on far pointers is problematic: there can be up to 4096 different segment-offset address pairs pointing to one and the same physical address. To compare two far pointers, they must first be converted (normalized) to their 20-bit linear representation.
On C compilers targeting the 8086 processor family, far pointers were declared using a non-standard far qualifier. For example, char far *p;
defined a far pointer to a char. The difficulty of normalizing far pointers could be avoided with the non-standard huge qualifier.
Example of far pointer:
#include<stdio.h> int main(){ char far *p =(char far *)0x55550005; char far *q =(char far *)0x53332225; *p = 80; (*p)++; printf("%d",*q); return 0; }
Output of the following program: 81; Because both addresses pointes to same location.
Physical Address = (value of segment register) * (10) + (value of offset).
Location pointed by pointer 'p' is : 0x5555 * 0x10 + 0x0005 = 0x55555
Location pointed by pointer 'q' is : 0x5333 * 0x10 + 0x2225 = 0x55555
So, p and q both points to same location 0x55555.